<!DOCTYPE html>
<html lang="en">
<head>
    {include file='public/header' /}
    <!-- Bootstrap Dropify CSS -->
    <link href="__PUBLIC__/admin/vendors/bower_components/dropify/dist/css/dropify.min.css" rel="stylesheet" type="text/css"/>
    <!-- Custom CSS -->
    {include file='public/comn_css' /}
</head>
<body>
<!--Preloader-->
<div class="preloader-it">
    <div class="la-anim-1"></div>
</div>
<!--/Preloader-->
<div class="wrapper  theme-5-active pimary-color-blue">

    <!-- Top Menu Items -->
    {include file='public/top_menu' /}
    <!-- /Top Menu Items -->

    <!-- Left Sidebar Menu -->
    {include file='public/sidebar' /}
    <!-- /Left Sidebar Menu -->

    <!-- Main Content -->
    <div class="page-wrapper">
        <div class="container-fluid">
            <!-- Title -->
            <div class="row heading-bg">
                <div class="col-lg-3 col-md-4 col-sm-4 col-xs-12">
                    <h5 class="txt-dark">数据备份</h5>
                </div>
                <!-- Breadcrumb -->
                <div class="col-lg-9 col-sm-8 col-md-8 col-xs-12">
                    <ol class="breadcrumb">
                        <li><a href="{:url('admin/index/index')}">系统首页</a></li>
                        <li class="active"><span>数据备份</span></li>
                    </ol>
                </div>
                <!-- /Breadcrumb -->
            </div>
            <!-- /Title -->

            <!-- Row -->
            <div class="row">
                <div class="col-lg-12 col-sm-12">
                    <div class="panel panel-default card-view">
                        <div class="panel-wrapper collapse in">
                            <div class="panel-body">
                                <div  class="pills-struct">
                                    <ul role="tablist" class="nav nav-pills" id="myTabs_6">
                                        <li class="active" role="presentation"><a aria-expanded="true"  data-toggle="tab" role="tab" id="tab_1" href="#tab_tab_1">数据备份</a></li>
                                        <li role="presentation"><a aria-expanded="true"  data-toggle="tab" role="tab" id="tab_2" href="#tab_tab_2">数据还原</a></li>
                                    </ul>
                                    <div class="tab-content" id="myTabContent_6">
                                        <div  id="tab_tab_1" class="tab-pane fade active in" role="tabpanel">
                                            <table class="table table-bordered">
                                                <thead>
                                                <tr>
                                                    <th>表名</th>
                                                    <th>引擎</th>
                                                    <th>数据条数</th>
                                                    <th>大小</th>
                                                    <th>创建时间</th>
                                                    <th>备注</th>
                                                </tr>
                                                </thead>
                                                <tbody>
                                                {notempty name='tables'}
                                                {foreach name='tables' item='value'}
                                                <tr>
                                                    <td>{$value.Name}</td>
                                                    <td>{$value.Engine}</td>
                                                    <td>{$value.Rows}</td>
                                                    <td>{$value.Data_length}</td>
                                                    <td>{$value.Create_time}</td>
                                                    <td>{$value.Comment}</td>
                                                </tr>
                                                {/foreach}
                                                {/notempty}
                                                </tbody>
                                            </table>
                                            <button class="btn btn-info" onclick="database_backup();">备份数据库</button>
                                        </div>
                                        <div  id="tab_tab_2" class="tab-pane fade" role="tabpanel">
                                            <table class="table table-bordered">
                                                <thead>
                                                <tr>
                                                    <th>文件名</th>
                                                    <th>大小</th>
                                                    <th>创建时间</th>
                                                    <th>操作</th>
                                                </tr>
                                                </thead>
                                                <tbody>
                                                {notempty name='list'}
                                                {foreach name='list' item='value'}
                                                <tr>
                                                    <td>{$value.filename}</td>
                                                    <td>{$value.size}</td>
                                                    <td>{$value.create_time|date='Y-m-d H:i', ###}</td>
                                                    <td>
                                                        <a href="javascript:;" class="mr-20" data-toggle="tooltip" data-original-title="导入数据库" onclick="import_database(this, '{$value.filename}');"> <i class="fa fa-mail-reply text-inverse m-r-10"></i> </a>
                                                        <a href="javascript:;" data-toggle="tooltip" data-original-title="删除" onclick="del(this, '{$value.filename}');"> <i class="fa  fa-trash-o text-danger"></i> </a>
                                                    </td>
                                                </tr>
                                                {/foreach}
                                                {/notempty}
                                                </tbody>
                                            </table>
                                        </div>
                                    </div>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
            <!-- /Row -->

        </div>
        <!-- Footer -->
        {include file='public/footer' /}
        <!-- /Footer -->

    </div>
    <!-- /Main Content -->

</div>
<!-- /#wrapper -->

<!-- JavaScript -->

<!-- jQuery -->
<script src="__PUBLIC__/admin/vendors/bower_components/jquery/dist/jquery.min.js"></script>

<!-- Bootstrap Core JavaScript -->
<script src="__PUBLIC__/admin/vendors/bower_components/bootstrap/dist/js/bootstrap.min.js"></script>

<!-- Slimscroll JavaScript -->
<script src="__PUBLIC__/admin/dist/js/jquery.slimscroll.js"></script>

<!-- Fancy Dropdown JS -->
<script src="__PUBLIC__/admin/dist/js/dropdown-bootstrap-extended.js"></script>

<!-- Owl JavaScript -->
<script src="__PUBLIC__/admin/vendors/bower_components/owl.carousel/dist/owl.carousel.min.js"></script>

<!-- Switchery JavaScript -->
<script src="__PUBLIC__/admin/vendors/bower_components/switchery/dist/switchery.min.js"></script>

<!-- Init JavaScript -->
{include file='public/comn_js' /}

<script src="__PUBLIC__/admin/dist/js/jquery.form.js"></script>
<script src="__PUBLIC__/admin/vendors/layer/layer.js"></script>
<script>
    function database_backup() {
        layer.confirm('您确定要备份数据库？', {
            btn: ['确定', '取消'],
            shade: [0.6, '#000']
        }, function () {
            layer.alert('备份期间请不要关闭或刷新页面！！！', function () {
                var index = layer.load(1, {shade: [0.6, '#000']});
                $.post("{:url('backup')}", {}, function (data) {
                    if (data)
                    {
                        layer.msg(data.msg, {}, function () {
                            window.location.reload();
                        })
                    }
                })
            });
        })
    }

    function del(obj, filename) {
        layer.confirm('您确定要删除该数据库备份？', {
            btn: ['确定', '取消'],
            shade: [0.6, '#000']
        }, function () {
            var index = layer.load(1, {shade: [0.6, '#000']});
            $.post("{:url('del')}", {filename:filename}, function (data) {
                if (data.status)
                {
                    layer.msg(data.msg, function () {
                        $(obj).parents('td').parents('tr').remove();
                        layer.closeAll();
                    })
                } else {
                    layer.msg(data.msg, function () {
                        layer.closeAll();
                    })
                }
            })
        })
    }

    function import_database(obj, filename) {
        layer.confirm('您确定要导入该数据库备份？', {
            btn: ['确定', '取消'],
            shade: [0.6, '#000']
        }, function () {
            layer.alert('导入期间请不要关闭或刷新页面！！！', function () {
                var index = layer.load(1, {shade: [0.6, '#000']});
                $.post("{:url('importDatabase')}", {filename:filename}, function (data) {
                    if (data)
                    {
                        layer.msg(data.msg, {}, function () {
                            window.location.reload();
                        })
                    }
                })
            });
        })
    }
</script>
</body>
</html>